﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Collections;
using LHS.Core.TableInfo;
using MS.Core.Constants.Objects;
using MS.Core.Base.Transaction;
using System.Collections.Specialized;

namespace LHS.Win
{
    public partial class frmKQXetNghiem : Form
    {
        LHS.Core.Clinical.ClinicalController objController = new LHS.Core.Clinical.ClinicalController();
        // Methods
        public frmKQXetNghiem(string SoID, string TenBenhNhan, string clrISN, bool insert)
        {
            this._SoID = SoID;
            this._TenBenhNhan = TenBenhNhan;
            this._clrISN = clrISN;
            this._insert = insert;
            this.InitializeComponent();
          
            this.dt = new DataTable("XetNghiemList");
            this.dt.Columns.Add("STT");
            this.dt.Columns.Add("Loại");
            this.dt.Columns.Add("Nhóm");
            this.dt.Columns.Add("Xét Nghiệm");
            this.dt.Columns.Add("Kết Quả");
            this.dt.Columns.Add("ISN");

            this.ds = new DataSet();

            List<ExpressionObject> param = new List<ExpressionObject>();
            param.Add(new ExpressionObject(InfoClinicalRecord.CLRISN, this._clrISN));
            DataTable dtAnalyzeResult = objController.GetData("vw_AnalyzeResult", param);

            //chua hieu ro doan duoi lam gi???
            //for (int i = 0; i < this.dt.Rows.Count; i++)
            //{
            //    if (this.dt.Rows[i]["ISN"].ToString() == this.txtISN.Text)
            //    {
            //        return;
            //    }
            //}
            for (int j = 0; j < dtAnalyzeResult.Rows.Count; j++)
            {
                DataRow row = this.dt.NewRow();
                row[0] = (j + 1).ToString();
                row[1] = dtAnalyzeResult.Rows[j]["nlpNameLevelOne"].ToString();
                row[2] = dtAnalyzeResult.Rows[j]["nlpNameLevelTwo"].ToString();
                row[3] = dtAnalyzeResult.Rows[j]["nlpNameLevelThree"].ToString();
                row[4] = dtAnalyzeResult.Rows[j][InfoAnalyzeResult.NLRRESULT].ToString();
                row[5] = dtAnalyzeResult.Rows[j][InfoAnalyzeResult.NLPISN].ToString();
                if ((row[1].ToString() == "") && (row[2].ToString() == ""))
                {
                    row[1] = row[3].ToString();
                    row[2] = row[3].ToString();
                }
                if ((row[1].ToString() == "") && (row[2].ToString() != ""))
                {
                    row[2] = dtAnalyzeResult.Rows[j]["nlpNameLevelTwo"].ToString();
                    row[1] = row[2].ToString();
                }
                this.dt.Rows.Add(row);
            }
            //this.ds.Tables.Clear();
            this.ds.Tables.Add(this.dt);
            this.dataGrid1.DataSource = this.ds;
            this.dataGrid1.SetDataBinding(this.ds, "XetNghiemList");
            this.loadDataGrid();
        }

        private void btAdd_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.dt.Rows.Count; i++)
            {
                if (this.dt.Rows[i]["ISN"].ToString() == this.txtISN.Text)
                {
                    return;
                }
            }
            if (this.check())
            {
                DataRow row = this.dt.NewRow();
                ArrayList list = new ArrayList();
                this.count = this.dt.Rows.Count + 1;
                list.Add(this.count.ToString());
                list.Add(this.txtXetNghiem.Text);
                list.Add(this.txtNhom.Text);
                list.Add(this.txtYeuCauXetNghiem.Text);
                list.Add(this.txtKetQua.Text);
                list.Add(this.txtISN.Text);
                this.arrISN.Add(this.txtISN.Text);
                row[0] = list[0];
                row[1] = list[1];
                row[2] = list[2];
                row[3] = list[3];
                row[4] = list[4];
                row[5] = list[5];
                this.dt.Rows.Add(row);
                this.loadDataSet();
                this.txtKetQua.Text = "";
                this.txtNhom.Text = "";
                this.txtXetNghiem.Text = "";
                this.txtYeuCauXetNghiem.Text = "";
            }
        }

        private void btExit_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btLuu_Click(object sender, EventArgs e)
        {
            if (((this.dataGrid1.DataSource != null) && (this.ds.Tables["XetNghiemList"].Rows.Count != 0)) && (MessageBox.Show("Bạn có muốn lưu xét nghiệm của bệnh nhân này không?", "Lưu Xét Nghiệm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes))
            {
                TransactionManager trans = TransactionManager.ThreadTransactionMgr();
                try
                {
                    trans.BeginTransaction();
                    List<ExpressionObject> paramDelAnalyzeResult = new List<ExpressionObject>();
                    paramDelAnalyzeResult.Add(new ExpressionObject(InfoAnalyzeResult.CLRISN, this._clrISN));
                    objController.DeleteRow(InfoAnalyzeResult.TABLENAME, paramDelAnalyzeResult);

                    for (int i = 0; i < this.ds.Tables["XetNghiemList"].Rows.Count; i++)
                    {
                        string str = this.ds.Tables["XetNghiemList"].Rows[i][3].ToString();
                        string str2 = this.ds.Tables["XetNghiemList"].Rows[i][4].ToString();
                        string str3 = this._clrISN;

                        ListDictionary param = new ListDictionary();
                        param.Add(InfoAnalyzePatient.NLPNAME, str);
                        param.Add(InfoAnalyzeResult.CLRISN, str3);
                        param.Add(InfoAnalyzeResult.NLRRESULT, str2);
                        objController.Exec_StoreProc("sp_AnalyzeResult_Insert", param);
                    }
                    trans.CommitTransaction();
                }
                catch (Exception ex)
                {
                    trans.RollbackTransaction();
                    Class.ShowException(ex);
                }
                MessageBox.Show("Kết quả xét nghiệm đã lưu", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
        }

        private void btThoat_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btUpdate_Click(object sender, EventArgs e)
        {
            if ((this.dataGrid1.DataSource != null) && (this.ds.Tables["XetNghiemList"].Rows.Count != 0))
            {
                if (this.txtYeuCauXetNghiem.Text == "")
                {
                    MessageBox.Show("Vui lòng chọn tên xét nghiệm từ danh sách nhập", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }
                else
                {
                    for (int i = 0; i < this.ds.Tables["XetNghiemList"].Rows.Count; i++)
                    {
                        if (this.ds.Tables["XetNghiemList"].Rows[i]["STT"].ToString() == this.txtSTT.Text)
                        {
                            this.ds.Tables["XetNghiemList"].Rows[i][1] = this.txtXetNghiem.Text;
                            this.ds.Tables["XetNghiemList"].Rows[i][2] = this.txtNhom.Text;
                            this.ds.Tables["XetNghiemList"].Rows[i][3] = this.txtYeuCauXetNghiem.Text;
                            this.ds.Tables["XetNghiemList"].Rows[i][4] = this.txtKetQua.Text;
                            this.ds.Tables["XetNghiemList"].Rows[i][5] = this.txtISN.Text;
                        }
                    }
                    this.txtKetQua.Text = "";
                    this.txtNhom.Text = "";
                    this.txtXetNghiem.Text = "";
                    this.txtYeuCauXetNghiem.Text = "";
                }
            }
        }

        private void btXoa_Click(object sender, EventArgs e)
        {
            if ((this.dataGrid1.DataSource != null) && (this.ds.Tables["XetNghiemList"].Rows.Count != 0))
            {
                if (this.txtYeuCauXetNghiem.Text == "")
                {
                    MessageBox.Show("Vui lòng chọn tên xét nghiệm từ danh sách nhập", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }
                else
                {
                    this.ds.Tables["XetNghiemList"].Rows[this.dataGrid1.CurrentRowIndex].Delete();
                    this.arrISN.Remove(this.txtISN.Text);
                    for (int i = 0; i < this.ds.Tables["XetNghiemList"].Rows.Count; i++)
                    {
                        if (this.ds.Tables["XetNghiemList"].Rows.Count == 0)
                        {
                            this.dataGrid1.DataSource = null;
                            return;
                        }
                        this.ds.Tables["XetNghiemList"].Rows[i]["STT"] = i + 1;
                    }
                    this.txtKetQua.Text = "";
                    this.txtNhom.Text = "";
                    this.txtXetNghiem.Text = "";
                    this.txtYeuCauXetNghiem.Text = "";
                }
            }
        }

        public bool check()
        {
            if (this.txtYeuCauXetNghiem.Text == "")
            {
                MessageBox.Show("Vui lòng chọn mẫu xét nghiệm từ danh sách", "Lỗi Nhập", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (this.txtKetQua.Text == "")
            {
                MessageBox.Show("Vui lòng nhập kết quả", "Lỗi Nhập", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            return true;
        }

        private void dataGrid1_MouseUp(object sender, MouseEventArgs e)
        {
            if ((this.dataGrid1.DataSource != null) && ((e.Button == MouseButtons.Left) && (this.dataGrid1.HitTest(e.X, e.Y).Type == DataGrid.HitTestType.RowHeader)))
            {
                this.txtXetNghiem.Text = this.ds.Tables["XetNghiemList"].Rows[this.dataGrid1.CurrentRowIndex]["Loại"].ToString();
                this.txtYeuCauXetNghiem.Text = this.ds.Tables["XetNghiemList"].Rows[this.dataGrid1.CurrentRowIndex]["Xét Nghiệm"].ToString();
                this.txtNhom.Text = this.ds.Tables["XetNghiemList"].Rows[this.dataGrid1.CurrentRowIndex]["Nhóm"].ToString();
                this.txtKetQua.Text = this.ds.Tables["XetNghiemList"].Rows[this.dataGrid1.CurrentRowIndex]["Kết Quả"].ToString();
                this.txtSTT.Text = this.ds.Tables["XetNghiemList"].Rows[this.dataGrid1.CurrentRowIndex]["STT"].ToString();
                this.txtISN.Text = this.ds.Tables["XetNghiemList"].Rows[this.dataGrid1.CurrentRowIndex][5].ToString();
            }
        }

        private void frmKQXetNghiem_Load(object sender, EventArgs e)
        {
            if (this._insert)
            {
                this.panel1.Visible = true;
                this.panel2.Visible = false;
                this.txtID.Text = this._SoID;
                this.txtTenBenhNhan.Text = this._TenBenhNhan;
                this.LoadXetNghiem();
            }
            else
            {
                this.panel1.Visible = false;
                this.panel2.Visible = true;
                this.txtIDXem.Text = this._SoID;
                this.txtTenXem.Text = this._TenBenhNhan;
                base.Height = 400;
                base.Width = 700;

                List<ExpressionObject> param = new List<ExpressionObject>();
                param.Add(new ExpressionObject( InfoClinicalRecord.CLRISN, this._clrISN));
                DataTable dtAnalyzeResult = objController.GetData("vw_AnalyzeResult", param);

                if (dtAnalyzeResult != null && dtAnalyzeResult.Rows.Count > 0)
                {
                    for (int i = 0; i < dtAnalyzeResult.Rows.Count; i++)
                    {
                        dtAnalyzeResult.Rows[i]["nlpISNLevelOne"] = i + 1;
                    }

                    DataSet dsAnalyzeResult = new DataSet();
                    dsAnalyzeResult.Tables.Add(dtAnalyzeResult);
                    this.dgXem.DataSource = dsAnalyzeResult;
                    this.dgXem.SetDataBinding(dsAnalyzeResult, "vw_AnalyzeResult");
                    this.dgXem.TableStyles.Clear();
                    this.loadDataGrid2();
                }
            }
        }

        private void insertChildNode(string strName, DataRow row)
        {
            this.node2 = new MyNode(row);
            this.node2.Text = strName;
        }

        private void insertChildNode3(string strName, DataRow row)
        {
            this.node3 = new MyNode(row);
            this.node3.Text = strName;
        }

        private void insertChildNode4(string strName, DataRow row)
        {
            this.node4 = new MyNode(row);
            this.node4.Text = strName;
        }

        private void insertChildNode5(string strName, DataRow row)
        {
            this.node5 = new MyNode(row);
            this.node5.Text = strName;
        }

        private void insertParentNode(string strName, DataRow row)
        {
            this.node = new MyNode(row);
            this.node.Text = strName;
        }

        public void loadDataGrid()
        {
            DataGridTableStyle table = new DataGridTableStyle();
            table.MappingName = "XetNghiemList";
            table.AlternatingBackColor = Color.AliceBlue;
            table.HeaderForeColor = Color.Maroon;
            table.GridLineColor = Color.CornflowerBlue;
            DataGridTextBoxColumn column = new DataGridTextBoxColumn();
            column.MappingName = "STT";
            column.HeaderText = " STT";
            column.Width = 50;
            table.GridColumnStyles.Add(column);
            column.Alignment = HorizontalAlignment.Center;
            DataGridTextBoxColumn column2 = new DataGridTextBoxColumn();
            column2.MappingName = "Loại";
            column2.HeaderText = "      Loại Xét Nghiệm";
            column2.Width = 180;
            column2.NullText = string.Empty;
            table.GridColumnStyles.Add(column2);
            column2.Alignment = HorizontalAlignment.Center;
            DataGridTextBoxColumn column3 = new DataGridTextBoxColumn();
            column3.MappingName = "Nhóm";
            column3.HeaderText = "        Nhóm";
            column3.Width = 150;
            column3.NullText = string.Empty;
            column3.Alignment = HorizontalAlignment.Center;
            table.GridColumnStyles.Add(column3);
            DataGridTextBoxColumn column4 = new DataGridTextBoxColumn();
            column4.MappingName = "Xét Nghiệm";
            column4.HeaderText = "  Xét Nghiệm";
            column4.Width = 120;
            column4.NullText = string.Empty;
            column4.Alignment = HorizontalAlignment.Center;
            table.GridColumnStyles.Add(column4);
            DataGridTextBoxColumn column5 = new DataGridTextBoxColumn();
            column5.MappingName = "Kết Quả";
            column5.HeaderText = "       Kết Quả";
            column5.Width = 180;
            column5.NullText = string.Empty;
            column5.Alignment = HorizontalAlignment.Center;
            table.GridColumnStyles.Add(column5);
            DataGridTextBoxColumn column6 = new DataGridTextBoxColumn();
            column6.MappingName = "ISN";
            column6.HeaderText = "";
            column6.Width = 0;
            column6.NullText = string.Empty;
            column6.Alignment = HorizontalAlignment.Center;
            table.GridColumnStyles.Add(column6);
            this.dataGrid1.TableStyles.Add(table);
            table.AllowSorting = false;
        }

        public void loadDataGrid2()
        {
            DataGridTableStyle table = new DataGridTableStyle();
            table.MappingName = "vw_AnalyzeResult";
            table.AlternatingBackColor = Color.AliceBlue;
            table.HeaderForeColor = Color.Maroon;
            table.GridLineColor = Color.CornflowerBlue;
            DataGridTextBoxColumn column = new DataGridTextBoxColumn();
            column.MappingName = "nlpISNLevelOne";
            column.HeaderText = " STT";
            column.Width = 50;
            table.GridColumnStyles.Add(column);
            column.Alignment = HorizontalAlignment.Center;
            DataGridTextBoxColumn column2 = new DataGridTextBoxColumn();
            column2.MappingName = "nlpNameLevelOne";
            column2.HeaderText = "      Loại Xét Nghiệm";
            column2.Width = 180;
            column2.NullText = string.Empty;
            table.GridColumnStyles.Add(column2);
            column2.Alignment = HorizontalAlignment.Center;
            DataGridTextBoxColumn column3 = new DataGridTextBoxColumn();
            column3.MappingName = "nlpNameLevelTwo";
            column3.HeaderText = "         Nhóm";
            column3.Width = 150;
            column3.NullText = string.Empty;
            column3.Alignment = HorizontalAlignment.Center;
            table.GridColumnStyles.Add(column3);
            DataGridTextBoxColumn column4 = new DataGridTextBoxColumn();
            column4.MappingName = "nlpNameLevelThree";
            column4.HeaderText = "  Xét Nghiệm";
            column4.Width = 120;
            column4.NullText = string.Empty;
            column4.Alignment = HorizontalAlignment.Center;
            table.GridColumnStyles.Add(column4);
            DataGridTextBoxColumn column5 = new DataGridTextBoxColumn();
            column5.MappingName = InfoAnalyzeResult.NLRRESULT;
            column5.HeaderText = "       Kết Quả";
            column5.Width = 180;
            column5.NullText = string.Empty;
            column5.Alignment = HorizontalAlignment.Center;
            table.GridColumnStyles.Add(column5);
            this.dgXem.TableStyles.Add(table);
            table.AllowSorting = false;
        }

        public void loadDataSet()
        {
            this.ds.Tables.Clear();
            this.ds.Tables.Add(this.dt);
            this.dataGrid1.TableStyles.Clear();
            this.dataGrid1.DataSource = this.ds;
            this.dataGrid1.SetDataBinding(this.ds, "XetNghiemList");
            this.loadDataGrid();
        }

        private void LoadXetNghiem()
        {
            if (arrPltISN != null)
                this.arrPltISN.Clear();
            if (arrPltName != null)
                this.arrPltName.Clear();
            if (arrCha != null)
                this.arrCha.Clear();

            ArrayList arrColumn1 = new ArrayList();
            arrColumn1.Add("nlpISNLevelOne");
            arrColumn1.Add("nlpNameLevelOne");
            List<ExpressionObject> param1 = new List<ExpressionObject>();
            param1.Add(new ExpressionObject("nlpNameLevelOne", "is not null", ExpressionObject.eSelectOperator.None));
            ListDictionary orderby1 = new ListDictionary();
            orderby1.Add("nlpNameLevelOne", "asc");
            DataTable dtAnalyzeTree1 = objController.GetData("vw_AnalyzeTree", true, arrColumn1, param1, orderby1);

            if (dtAnalyzeTree1 != null)
            {
                for (int i = 0; i < dtAnalyzeTree1.Rows.Count; i++)
                {
                    this.arrPltISN.Add(dtAnalyzeTree1.Rows[i][0].ToString());
                    this.arrPltName.Add(dtAnalyzeTree1.Rows[i][1].ToString());
                }
                for (int j = 0; j < this.arrPltISN.Count; j++)
                {
                    this.insertParentNode(this.arrPltName[j].ToString(), dtAnalyzeTree1.Rows[j]);
                    this.arrOng.Add(this.arrPltName[j].ToString());
                    this.tvBenh.Nodes.Add(this.node);

                    ArrayList arrColumn2 = new ArrayList();
                    arrColumn2.Add("nlpISNLevelTwo");
                    arrColumn2.Add("nlpNameLeveltwo");
                    List<ExpressionObject> param2 = new List<ExpressionObject>();
                    param2.Add(new ExpressionObject("nlpNameLeveltwo", "is not null", ExpressionObject.eSelectOperator.None));
                    param2.Add(new ExpressionObject("nlpISNLevelOne", this.arrPltISN[j].ToString()));
                    ListDictionary orderby2 = new ListDictionary();
                    orderby2.Add("nlpNameLevelTwo", "asc");
                    DataTable dtAnalyzeTree2 = objController.GetData("vw_AnalyzeTree", true, arrColumn2, param2, orderby2);

                    for (int k = 0; k < dtAnalyzeTree2.Rows.Count; k++)
                    {
                        this.tvBenh.SelectedNode = this.node;
                        this.arrOng.Remove(this.arrPltName[j].ToString());
                        this.insertChildNode(dtAnalyzeTree2.Rows[k]["nlpNameLevelTwo"].ToString(), dtAnalyzeTree2.Rows[k]);
                        this.tvBenh.SelectedNode.Nodes.Add(this.node2);
                        this.arrCha.Add(dtAnalyzeTree2.Rows[k]["nlpNameLevelTwo"].ToString());

                        ArrayList arrColumn3 = new ArrayList();
                        arrColumn3.Add("nlpISNLevelThree");
                        arrColumn3.Add("nlpNameLevelThree");
                        List<ExpressionObject> param3 = new List<ExpressionObject>();
                        param3.Add(new ExpressionObject("nlpNameLevelthree", "is not null", ExpressionObject.eSelectOperator.None));
                        param3.Add(new ExpressionObject("nlpISNLevelTwo", dtAnalyzeTree2.Rows[k]["nlpISNLevelTwo"].ToString()));
                        ListDictionary orderby3 = new ListDictionary();
                        orderby3.Add("nlpNameLevelThree", "asc");
                        DataTable dtAnalyzeTree3 = objController.GetData("vw_AnalyzeTree", true, arrColumn3, param3, orderby3);
                      
                        this.tvBenh.SelectedNode = this.node2;
                        for (int m = 0; m < dtAnalyzeTree3.Rows.Count; m++)
                        {
                            this.arrCha.Remove(k);
                            this.tvBenh.SelectedNode = this.node2;
                            this.insertChildNode3(dtAnalyzeTree3.Rows[m]["nlpNameLevelThree"].ToString(), dtAnalyzeTree3.Rows[m]);
                            this.tvBenh.SelectedNode.Nodes.Add(this.node3);

                            ArrayList arrColumn4 = new ArrayList();
                            arrColumn4.Add("nlpISNLevelFourth");
                            arrColumn4.Add("nlpNameLevelFourth");
                            List<ExpressionObject> param4 = new List<ExpressionObject>();
                            param4.Add(new ExpressionObject("nlpNameLevelFourth", "is not null", ExpressionObject.eSelectOperator.None));
                            param4.Add(new ExpressionObject("nlpISNLevelThree", dtAnalyzeTree3.Rows[m]["nlpISNLevelThree"].ToString()));
                            ListDictionary orderby4 = new ListDictionary();
                            orderby4.Add("nlpNameLevelFourth", "asc");
                            DataTable dtAnalyzeTree4 = objController.GetData("vw_AnalyzeTree", true, arrColumn4, param4, orderby4);

                            this.tvBenh.SelectedNode = this.node3;
                            for (int n = 0; n < dtAnalyzeTree4.Rows.Count; n++)
                            {
                                this.tvBenh.SelectedNode = this.node3;
                                this.insertChildNode4(dtAnalyzeTree4.Rows[n]["nlpNameLevelFourth"].ToString(), dtAnalyzeTree4.Rows[n]);
                                this.tvBenh.SelectedNode.Nodes.Add(this.node4);

                                ArrayList arrColumn5 = new ArrayList();
                                arrColumn5.Add("nlpISNLevelFifth");
                                arrColumn5.Add("nlpNameLevelFifth");
                                List<ExpressionObject> param5 = new List<ExpressionObject>();
                                param5.Add(new ExpressionObject("nlpNameLevelFifth", "is not null", ExpressionObject.eSelectOperator.None));
                                param5.Add(new ExpressionObject("nlpISNLevelFourth", dtAnalyzeTree4.Rows[n]["nlpISNLevelFourth"].ToString()));
                                ListDictionary orderby5 = new ListDictionary();
                                orderby5.Add("nlpNameLevelFifth", "asc");
                                DataTable dtAnalyzeTree5 = objController.GetData("vw_AnalyzeTree", true, arrColumn5, param5, orderby5);

                                this.tvBenh.SelectedNode = this.node4;
                                for (int num6 = 0; num6 < dtAnalyzeTree5.Rows.Count; num6++)
                                {
                                    this.tvBenh.SelectedNode = this.node4;
                                    this.insertChildNode5(dtAnalyzeTree5.Rows[num6]["nlpNameLevelFifth"].ToString(), dtAnalyzeTree5.Rows[num6]);
                                    this.tvBenh.SelectedNode.Nodes.Add(this.node5);
                                }
                            }
                        }
                    }
                }
                this.tvBenh.CollapseAll();
            }
        }

        private void tvBenh_DoubleClick(object sender, EventArgs e)
        {
            for (int i = 0; i < this.arrISN.Count; i++)
            {
                MyNode selectedNode = (MyNode)this.tvBenh.SelectedNode;
                string str2 = selectedNode.DataRow[0].ToString();
                if (this.arrISN[i].ToString() == str2)
                {
                    return;
                }
            }
            for (int j = 0; j < this.arrPltName.Count; j++)
            {
                if (this.tvBenh.SelectedNode.Text.ToString() == this.arrPltName[j].ToString())
                {
                    this.txtYeuCauXetNghiem.Text = this.txtNhom.Text = this.txtXetNghiem.Text = "";
                    return;
                }
                for (int k = 0; k < this.arrOng.Count; k++)
                {
                    if (this.tvBenh.SelectedNode.Text.ToString() == this.arrOng[k].ToString())
                    {
                        MyNode node2 = (MyNode)this.tvBenh.SelectedNode;
                        this.txtYeuCauXetNghiem.Text = this.txtNhom.Text = this.txtXetNghiem.Text = this.tvBenh.SelectedNode.Text.ToString();
                        this.txtISN.Text = node2.DataRow[0].ToString();
                        return;
                    }
                }
            }
            if (!this.tvBenh.SelectedNode.Parent.IsSelected && (this.tvBenh.SelectedNode.Nodes.Count == 0))
            {
                for (int m = 0; m < this.arrCha.Count; m++)
                {
                    if (this.tvBenh.SelectedNode.Text.ToString() == this.arrCha[m].ToString())
                    {
                        MyNode node3 = (MyNode)this.tvBenh.SelectedNode;
                        this.txtYeuCauXetNghiem.Text = this.txtNhom.Text = this.tvBenh.SelectedNode.Text.ToString();
                        this.txtXetNghiem.Text = this.tvBenh.SelectedNode.Parent.Text.ToString();
                        this.txtISN.Text = node3.DataRow[0].ToString();
                        return;
                    }
                }
                MyNode node4 = (MyNode)this.tvBenh.SelectedNode;
                this.txtISN.Text = node4.DataRow[0].ToString();
                this.txtYeuCauXetNghiem.Text = this.tvBenh.SelectedNode.Text.ToString();
                this.txtXetNghiem.Text = this.tvBenh.SelectedNode.Parent.Parent.Text.ToString();
                this.txtNhom.Text = this.tvBenh.SelectedNode.Parent.Text.ToString();
            }
        }

        private void txtNhom_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = true;
        }

    }
}